import os


def get_dir_size(dir_path, unit='MB'):
    total_size = 0
    for root, dirs, files in os.walk(dir_path):
        for file in files:
            file_path = os.path.join(root, file)
            total_size += os.path.getsize(file_path)

    match unit:
        case 'KB':
            total_size /= 1024
        case 'MB':
            total_size /= 1024 * 1024
        case 'GB':
            total_size /= 1024 * 1024 * 1024
    return str(round(total_size, 2)) + unit


def get_sub_dirs(parent_dir_path):
    sub_dirs = []
    for entry in os.scandir(parent_dir_path):
        if entry.is_dir():
            sub_dirs.append(entry.path)
    return sub_dirs


if __name__ == '__main__':
    dir_path = 'C:/'
    for entry in os.scandir(dir_path):
        if entry.is_dir():
            print(f"{entry.path} = {get_dir_size(entry.path, 'GB')}")
    # size = get_dir_size(dir_path)
    # print('文件夹大小为：', size, '字节')
